//package com.example.exam.controller;
//
//import com.example.exam.entity.DTO.CertificateDTO;
//import com.example.exam.utils.AmazeS3Utils;
//import com.example.exam.utils.FileUtils;
//import jdk.internal.util.xml.impl.Input;
//import lombok.extern.log4j.Log4j2;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.*;
//import org.springframework.web.multipart.MultipartFile;
//
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.InputStream;
//import java.io.OutputStream;
//
///**
// * @author zhang
// */
//@RestController
//@RequestMapping("/certificate")
//@Log4j2
//public class CertificateController {
//    @Autowired
//    private AmazeS3Utils amazeS3Utils;
//
//    @PostMapping("/create")
//    public String create(@RequestParam("file") MultipartFile file, @RequestBody CertificateDTO certificateDTO) throws IOException {
//        String fileName = file.getOriginalFilename();
//        amazeS3Utils.streamUpload(fileName,file.getInputStream());
//
//        return "create";
//    }
//
//    @GetMapping("/{name}")
//    public String certificate(@PathVariable String name, HttpServletResponse response) throws IOException {
//        try (InputStream inputStream = amazeS3Utils.download(name)) {
//            response.setContentType("application/octet-stream");
//            response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\"");
//            OutputStream outputStream = response.getOutputStream();
//            byte[] buffer = new byte[1024];
//            int bytesRead;
//            while ((bytesRead = inputStream.read(buffer)) != -1) {
//                outputStream.write(buffer, 0, bytesRead);
//            }
//        }
//        return name;
//    }
//
//    @GetMapping("/download/{name}")
//    public String download(@PathVariable String name,HttpServletResponse response ) throws IOException {
//        InputStream inputStream = amazeS3Utils.download(name);
//        OutputStream outputStream = response.getOutputStream();
//        response.setContentType("application/octet-stream");
//        response.setHeader("Content-Disposition", "attachment; filename=\"" + name + "\"");
//        byte[] buffer = new byte[1024];
//        int bytesRead;
//        while ((bytesRead = inputStream.read(buffer)) != -1) {
//            outputStream.write(buffer, 0, bytesRead);
//        }
//        return "";
//    }
//
//}
